# 1、读取数据
from kafka import KafkaProducer

with open("../data/students.json",mode="r",encoding="utf-8") as f:
    lines = [line.strip() for line in f.readlines()]


# 2、创建生产者
producer = KafkaProducer(bootstrap_servers='master:9092')

# 循环生产数据
for line in lines:
    # 如果topic不存在会自动创建一个分区为1副本为1的topic
    producer.send(topic="students", value=line.encode("utf-8"))
    producer.flush()

producer.close()

# print("数加".encode("utf-8").decode("utf-8"))